<?php
class AuDb extends AuSource{
	public function shelfMapper($shelf){
		$criteria = new CDbCriteria;
		if (is_array($shelf->primary)){
			$criteria->addInCondition('id',$shelf->primary);
		}else{
			$criteria->compare('id', $shelf->primary);
		}
		return $criteria;
	}
	
	public function find($shelf = null){
		$auctionBase = new AuctionBaseDatas();
		$this->result = $auctionBase->find($this->shelfMapper($shelf));
		if (!empty($this->result)) {
			$this->result = $this->setPrototypeAttrs($this->result->attributes)->getPrototype();
		}
		return $this->result;
	}
	
	public function findAll($shelf = null){
		$auctionBase = new AuctionBaseDatas();
		$this->result = $auctionBase->findAll($this->shelfMapper($shelf));
		$className = $this->getPrototype()->className();
		$findAll = array();
		if (!empty($this->result)) {
			foreach ($this->result as $ar){
				$tempAr = new $className();
				$tempAr->attributes($this->buildMapperValue($ar->attributes));
				$findAll[] = $tempAr;
			}
		}
		$this->result = $findAll;
		return $this->result;
	}
	
}